package com.yida.gwj.vote.outside.controller;

import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.gwj.vote.outside.domain.GwjVoteProject;
import com.yida.gwj.vote.outside.domain.dto.GwjEVoteProjectStatisticsDataDTO;
import com.yida.gwj.vote.outside.domain.dto.GwjVoteProjectListDTO;
import com.yida.gwj.vote.outside.domain.request.GwjVoteProjectQueryRequest;
import com.yida.gwj.vote.outside.enums.GwjVoteInitiateTypeEnum;
import com.yida.gwj.vote.outside.enums.GwjVoteStatusEnum;
import com.yida.gwj.vote.outside.service.IGwjVoteProjectService;
import com.yida.gwj.vote.outside.service.IGwjVoteStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 投票字典Controller
 *
 * @author lqq
 * @date 2023-05-08
 */
@RestController
@RequestMapping("/publicize")
@Api(tags = "投票公示接口")
public class GwjVotePublicizeController extends BaseController {

    @Resource
    private IGwjVoteProjectService voteProjectService;

    @Resource
    private IGwjVoteStatisticsService voteProjectStatistics;

    @ApiOperation(value = "投票信息公示列表", response = GwjVoteProjectListDTO.class)
    @GetMapping("/e/list")
    public TableDataInfo ePublicizeList() {
        startPage();
        List<GwjVoteProject> list = voteProjectService.selectVotePublicizeProjectList(new GwjVoteProjectQueryRequest() {{
            setInitiateType(GwjVoteInitiateTypeEnum.E_VOTE.getCode());
            setVoteStatus(GwjVoteStatusEnum.VOTE_ING.getCode());
        }});
        return getDataDtoTable(list, GwjVoteProjectListDTO.class);
    }

    @ApiOperation(value = "投票信息公示列表投票详情", response = GwjEVoteProjectStatisticsDataDTO.class)
    @GetMapping("/e/{voteId}")
    public AjaxResult votePublicizeDetail(@PathVariable Long voteId) {
        return AjaxResult.success(new GwjEVoteProjectStatisticsDataDTO() {{
            //统计投票基础数据
            setBaseData(voteProjectStatistics.eVoteProjectStatisticsBaseData(voteId));
            //统计投票表决项数据
            setItemData(voteProjectStatistics.voteResultDetailStatistics(voteId));
        }});
    }
}
